# -*- coding: utf-8 -*-
#   处理字符串，数字转换等函数
# @Time    ： 2024/4/9  10:23
# @Auther  ： 徐良
# File     :  baseFunction.py
from PySide6.QtCore import QDate, QTime, QDateTime

# 字符串加单引号
def quote(string):
    """
    返回带单引号的字符串
    :param string:
    :return:
    """
    return "'{}'".format(string)


# 保留浮点数指定的小数位
def getNumberRound(num, decimal=None):
    """
    返回 浮点数num的四舍五入值
    :param num:
    :param decimal:
    :return:
    """
    if decimal is None:
        ret = "{:.2f}".format(num)
    elif decimal == 1:
        ret = "{:.1f}".format(num)
    elif decimal == 2:
        ret = "{:.2f}".format(num)
    elif decimal == 3:
        ret = "{:.3f}".format(num)
    elif decimal == 4:
        ret = "{:.4f}".format(num)
    else:
        ret = "{:.2f}".format(num)

    return float(ret)


# 获取对象类型
def getInstanceType(obj):
    """
    返回对象的数据类型
    :param obj: 对象
    :return: int/str/QDate/QTime/float/QDateTime
    """

    if isinstance(obj, int):
        return 'int'
    elif isinstance(obj, str):
        return 'str'
    elif isinstance(obj, QDate):
        return 'QDate'
    elif isinstance(obj, QTime):
        return 'QTime'
    elif isinstance(obj, float):
        return 'float'
    elif isinstance(obj, QDateTime):
        return 'QDateTime'
    else:
        return None

# 转换点分（ss.dd）的字符串为列表
def getListFormStrByDot(ss):
    """
    将以 | 为分割符的字符串转换成列表
    :param ss:
    :return:
    """
    if ss is None or ss == '':
        return []
    s = ss.replace('#', '').replace('\n', '').replace('*', '').strip('')  # 清除#
    ret = s.split(',')
    return ret

def getListFormStrByVLine(ss):
    """
    将以 | 为分割符的字符串转换成列表
    :param ss:
    :return:
    """
    if ss is None or ss == '':
        return []
    s = ss.replace('#', '').replace('\n', '').replace('*', '').strip()  # 清除#
    ret = s.split('|')
    ret = [item.strip() for item in ret]
    return ret



